package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WorkerView;
import com.ruoyi.system.service.IWorkerViewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * VIEWController
 *
 * @author ruoyi
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/system/workerview")
public class WorkerViewController extends BaseController
{
    @Autowired
    private IWorkerViewService workerViewService;

    /**
     * 查询VIEW列表
     */
    @PreAuthorize("@ss.hasPermi('system:workerview:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkerView workerView)
    {
        startPage();
        List<WorkerView> list = workerViewService.selectWorkerViewList(workerView);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('system:workerview:list')")
    @Anonymous
    @GetMapping("/charts")
    public List<WorkerView>  charts(){
        return workerViewService.selectWorkerViewList(null);
    }

    @Anonymous
    @GetMapping("/frontList")
    public AjaxResult frontList(){
        return success(workerViewService.selectWorkerViewList(null));
    }
    /**
     * 导出VIEW列表
     */
    @PreAuthorize("@ss.hasPermi('system:workerview:export')")
    @Log(title = "VIEW", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkerView workerView)
    {
        List<WorkerView> list = workerViewService.selectWorkerViewList(workerView);
        ExcelUtil<WorkerView> util = new ExcelUtil<WorkerView>(WorkerView.class);
        util.exportExcel(response, list, "VIEW数据");
    }

    /**
     * 获取VIEW详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:workerview:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workerViewService.selectWorkerViewById(id));
    }

    /**
     * 新增VIEW
     */
    @PreAuthorize("@ss.hasPermi('system:workerview:add')")
    @Log(title = "VIEW", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkerView workerView)
    {
        return toAjax(workerViewService.insertWorkerView(workerView));
    }

    /**
     * 修改VIEW
     */
    @PreAuthorize("@ss.hasPermi('system:workerview:edit')")
    @Log(title = "VIEW", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkerView workerView)
    {
        return toAjax(workerViewService.updateWorkerView(workerView));
    }

    /**
     * 删除VIEW
     */
    @PreAuthorize("@ss.hasPermi('system:workerview:remove')")
    @Log(title = "VIEW", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workerViewService.deleteWorkerViewByIds(ids));
    }
}
